//
//  RevisonView.m
//  Rainbow
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RevisonView.h"

@implementation RevisonView

-(instancetype)initWithFrame:(CGRect)frame withCount:(NSInteger)count{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatViewWithCount:count];
    }
    return self;
    
}
-(void)creatViewWithCount:(NSInteger)count{
    for (NSInteger i = count; i > 0; i--) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50 * i, 50 * i)];
        view.center = self.center;
        view.backgroundColor = [UIColor colorWithRed:arc4random()%100/100.0 green:arc4random()%100/100.0    blue:arc4random()%100/100 alpha:1];
        [self addSubview:view];
    }
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changeColor) userInfo:nil repeats:YES];
    
        
    }
-(void)changeColor{
    NSArray *array = self.subviews;
    UIColor *temp = [[UIColor alloc]init];
    UIView *view = [array objectAtIndex:0];
    temp = view.backgroundColor;
    for (NSInteger i = 0; i < array.count-1 ; i++) {
        UIView *nowView = [array objectAtIndex:i];
        UIView *nextView = [array objectAtIndex:i+1];
        nowView.backgroundColor  = nextView.backgroundColor;
        
        
    }
    UIView *max = [array objectAtIndex:array.count - 1];
    max.backgroundColor = temp;
}
    
    

@end
